//
//  ProductInfoCell.m
//  LoveTrail
//
//  Created by DEV on 15/6/17.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "ProductInfoCell.h"
#import "UIImageView+WebCache.h"
#import "CommonMacro.h"
@interface ProductInfoCell()
@property (nonatomic, weak)UIImageView *imageView;
@property (nonatomic, weak)UILabel *productTitleLable;
@property (nonatomic, weak)UILabel *currentPriceLable;
@property (nonatomic, weak)UILabel *originalPriceLabel;
@property (nonatomic, weak)UILabel *saledNumLabel;

@end
@implementation ProductInfoCell

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        UIImageView *imageView = [[UIImageView alloc]init];
        [self addSubview:imageView];
        self.imageView = imageView;
        
        UILabel *productTitleLable = [[UILabel alloc]init];
        [self addSubview:productTitleLable];
        self.productTitleLable = productTitleLable;
        
        UILabel *currentPriceLable = [[UILabel alloc]init];
        [self addSubview:currentPriceLable];
        self.currentPriceLable = currentPriceLable;
        
        UILabel *originalPriceLabel = [[UILabel alloc]init];
        [self addSubview:originalPriceLabel];
        self.originalPriceLabel = originalPriceLabel;
        
        UILabel *saledNumLabel = [[UILabel alloc]init];
        [self addSubview:saledNumLabel];
        self.saledNumLabel = saledNumLabel;
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //此处frame先写死，以后真正的frame是根据传进来的data进行计算的。即元素有一个frame对象，包含frame及model.
    self.imageView.frame = CGRectMake(0, 0, self.frame.size.width, 80);
    self.productTitleLable.frame = CGRectMake(0, CGRectGetMaxY(self.imageView.frame), self.frame.size.width, 40);
    self.currentPriceLable.frame = CGRectMake(0, CGRectGetMaxY(self.productTitleLable.frame), 60, 40);
    self.originalPriceLabel.frame = CGRectMake(CGRectGetMidX(self.currentPriceLable.frame), self.currentPriceLable.frame.origin.y, 60, 40);
    self.saledNumLabel.frame = CGRectMake(self.frame.size.width - 100 - 10, self.currentPriceLable.frame.origin.y, 100, 40);
   [self valueForSubviews];
}

- (void)valueForSubviews
{
    [self.imageView setImageWithURL:[NSURL URLWithString:self.productInfoModel.imageUrl]];
    
    self.productTitleLable.text = self.productInfoModel.productTitle;
    
    self.currentPriceLable.text = self.productInfoModel.currentPrice;
    
    self.originalPriceLabel.text = self.productInfoModel.originalPrice;
    
    self.saledNumLabel.text = self.productInfoModel.saledNum;
    
}


@end
